package com.kla.power.controller;

import com.kla.power.config.LogPointer;
import com.kla.power.entity.NoticeEntity;
import com.kla.power.entity.UserEntity;
import com.kla.power.service.INoticeService;
import com.kla.power.util.RedisUtils;
import com.kla.power.util.ResultBody;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 工单通知 前端控制器
 * </p>
 * @author WuZH
 * @since 2023-06-24
 */
@RestController
@RequestMapping ("/notice")
@CrossOrigin (value = "*", maxAge = 3600)
public class NoticeController {

    @Resource
    private INoticeService iNoticeService;

    @RequestMapping ("queryList")
    @LogPointer ("查询通知列表")
    public ResultBody queryList ( @RequestBody NoticeEntity noticeEntity) {
        UserEntity userEntity = (UserEntity) RedisUtils.get ( noticeEntity.getToken () );
        noticeEntity.setUserId ( userEntity.getId () );
        List<NoticeEntity> noticeEntities = iNoticeService.queryList ( noticeEntity );
        return ResultBody.success ( noticeEntities );
    }

    /**
     * 查看一条通知，并修改状态为已读
     * @param noticeEntity
     * @return
     */
    @RequestMapping ("querySingle")
    @LogPointer("查询通知详情")
    public ResultBody querySingle (@RequestBody NoticeEntity noticeEntity) {
        noticeEntity = iNoticeService.querySingle ( noticeEntity );
        return ResultBody.success ( noticeEntity );
    }

}
